<template>
  <div class="line-chart-container">
    <div ref="lineChart" style="width: 100%; height: 300px;"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'LeaveLineChart',
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      const chart = echarts.init(this.$refs.lineChart)

      const option = {
        tooltip: {
          trigger: 'axis',
          formatter: '{b}<br/>{a0}: {c0}人<br/>{a1}: {c1}人'
        },
        legend: {
          data: ['请假人数', '调休人数'],
          top: 'bottom'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '15%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
          axisLine: {
            lineStyle: {
              color: '#999'
            }
          }
        },
        yAxis: {
          type: 'value',
          name: '人数',
          axisLine: {
            show: true,
            lineStyle: {
              color: '#999'
            }
          }
        },
        series: [
          {
            name: '请假人数',
            type: 'line',
            smooth: true,
            data: [12, 8, 19, 7, 12, 9, 25, 32, 21, 15, 12, 28],
            lineStyle: {
              width: 4,
              color: '#5470C6'
            },
            itemStyle: {
              color: '#5470C6'
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {offset: 0, color: 'rgba(84, 112, 198, 0.5)'},
                {offset: 1, color: 'rgba(84, 112, 198, 0.1)'}
              ])
            }
          },
          {
            name: '调休人数',
            type: 'line',
            smooth: true,
            data: [5, 6, 8, 4, 7, 5, 10, 15, 12, 8, 6, 14],
            lineStyle: {
              width: 4,
              color: '#91CC75'
            },
            itemStyle: {
              color: '#91CC75'
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {offset: 0, color: 'rgba(145, 204, 117, 0.5)'},
                {offset: 1, color: 'rgba(145, 204, 117, 0.1)'}
              ])
            }
          }
        ]
      }

      chart.setOption(option)

      window.addEventListener('resize', function () {
        chart.resize()
      })
    }
  }
}
</script>

<style scoped>
.line-chart-container {
  width: 100%;
}
</style>